#pragma once
#include <string>
#include"comLib\net.h"
#include<comLib\VideoInf.h>
#include <common\def.h>
#include <QThread>
#include <QSemaphore>
extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavdevice/avdevice.h"
#include <libswscale/swscale.h>
};

class CMp4Encode;
class CVideoEncoder;
class CInputDevices;
class DDesktopDecoder;
class VideoDXGICaptor;
class DNetClient;

class CVideoProcesser:public QThread
{
public:
	CVideoProcesser(QObject *parent=nullptr);
	void run() override;
	bool init(AVFormatContext *pFormatCtx);
	void stopThread();

private:
	AVFrame *getPicFrame(int width, int height, uint8_t *srcPic);
	AVFrame *getYuvFrame(int width,int height);
	void writePicFrame(int width, int height, uint8_t *srcPic);

	void initPicFrame(int width, int height);
	void initScreenDecode();

private:
	bool m_bRun = true;

	std::shared_ptr<EncoderInf> m_pVideoEncoder;
	std::shared_ptr<DecoderInf> m_pVideoDecoder;
	std::shared_ptr<CInputDevices> m_pInputDevices;
	std::shared_ptr<DDesktopDecoder> m_pDesktopDecoder;

	AVFrame *m_pImageFrame;
	AVFrame *m_pScreenFrame;
	AVFrame *m_pYuvFrame;
	SwsContext *m_pSwsContext;
	DNetClient *m_pNetClient;
	VideoDXGICaptor *m_pVideoDXGICaptor;

	QSemaphore m_ExitSignal;
};